<template>
  <div></div>
</template>

<script lang="ts" setup>
  import { unref } from 'vue';
  import { useRouter, useRoute } from 'vue-router';

  // 初始化路由实例
  const router = useRouter();
  const route = useRoute();

  // 获取当前路由和替换方法
  const currentRoute = route;
  const replace = router.replace;

  // 解构参数和查询
  const { params, query } = unref(currentRoute);
  const { path, _redirect_type = 'path' } = params || {};

  // 删除不需要的参数
  Reflect.deleteProperty(params, '_redirect_type');
  Reflect.deleteProperty(params, 'path');

  // 处理路径
  const _path = Array.isArray(path) ? path.join('/') : path;

  // 根据重定向类型执行跳转
  if (_redirect_type === 'name') {
    replace({
      name: _path,
      query,
      params,
    });
  } else {
    replace({
      path: _path.startsWith('/') ? _path : '/' + _path,
      query,
    });
  }
</script>
